import request from '@/utils/request'

export function postAction(url, data) {
  return request({
    url: url,
    method: 'post',
    data
  })
}

export function getAction(url, params) {
  return request({
    url: url,
    method: 'get',
    params: params
  })
}

//接口
export function fileDataDownloadIO(url, params) {
  return request({
    url: url,
    method: 'get',
    params,
    responseType: 'blob', //设置响应格式
    headers: {
      'Content-Type': 'application/force-download', //设置请求头，根据后台需要格式
    }
  })
}


export function putAction(url, data) {
  return request({
    url: url,
    method: 'put',
    data
  })
}

export function deleteAction(url, params) {
  return request({
    url: url,
    method: 'delete',
    params: params
  })
}

export function httpAction(url, method, data) {
  return request({
    url: url,
    method: method,
    data
  })
}

export function uploadMarkDownImg(url, data) {
  return request({
    url: url,
    method: 'post',
    data: data
  })
}

/**
 * 获取文件服务访问路径
 * @param avatar
 * @param subStr
 * @returns {*}
 */
export function getFileAccessHttpUrl(avatar, subStr) {
  if (!subStr) subStr = 'http'
  if (avatar && avatar.startsWith(subStr)) {
    return avatar
  } else {
    if (avatar && avatar.length > 0 && avatar.indexOf('[') === -1) {
      // return process.env.VUE_APP_BASE_API + 'https://wxmin.cn/ants/sys/common/static/' + avatar
      return process.env.VUE_APP_BASE_API + "/sys/common/static/" + avatar
      // return 'https://wxmin.cn/ants/sys/common/static/' + avatar
    }
  }
}

